package com.justreading.netty.protobuftcp;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;

import java.util.List;

/**
 * @author LYJ
 * @Description
 * @date 2021 年 11 月 09 日 下午8:14
 */
public class MyMessageDecoder extends ReplayingDecoder<Void> {

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        System.out.println("MyMessageDecoder 被调用");
        int size = in.readInt();
        byte[] content = new byte[size];
        in.readBytes(content);

        MessageProtocol messageProtocol = new MessageProtocol();
        messageProtocol.setLen(size);
        messageProtocol.setContent(content);

        out.add(messageProtocol);
    }
}
